package org.daidai.abstrusewriting.homepage.live.tools;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class ImageLivetask extends AsyncTask<String , Void ,Bitmap> {

    private Service service;
   public  void setService(Service service)
   {
       this.service=service;
   }
    @Override
    protected Bitmap doInBackground(String... strings) {
        String url = strings[0];
        try {
            HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
            connection.setRequestMethod("GET");
            connection.setDoInput(true);
            int code = connection.getResponseCode();
            if (code==200)
            {
                InputStream inputStream = connection.getInputStream();
                Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
                service.send(bitmap);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

}
